package com.zetyun.tiger.app.opac;

import com.zetyun.rt.meta.annotation.ActionMeta;
import com.zetyun.rt.sdk.action.MapAction;
import com.zetyun.rt.sdk.model.RtEvent;

import static com.zetyun.tiger.app.opac.FormatConstant.*;
import static com.zetyun.tiger.app.opac.FormatConstant.CB_EVENT_MINU;

@ActionMeta(
        id = "tiger.opac-day-hour-format",
        tags = {"opac"},
        category = "map",
        name = "Opac-Day-Hour-Format",
        description = "格式化日期、时间，增加 RT_EVENT_DATE、RT_EVENT_HOUR、RT_EVENT_MINU 三个字段",
        parameterClass = OpacParameter.class,
        status = ActionMeta.Status.PUBLIC
)
public class DayHourAction extends MapAction {
    @Override
    public RtEvent apply(RtEvent in) throws Exception {
        String fullDate = in.getField(RT_EVENT_TIME, String.class);
        String day = fullDate.substring(0, 10).replace("-", "");

        String hour = fullDate.substring(11, 13);
        String minute = fullDate.substring(14, 16);
        in.setValue(RT_EVENT_DATE, day);
        in.setValue(RT_EVENT_HOUR, hour);
        in.setValue(RT_EVENT_MINU, minute);
        return in;
    }
}
